﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Configuration;
using PersistentObject.SqlServer2012;
using PersistentObject.Common.Schema;
using PersistentObject.StudentTest.Entities;
using PersistentObject.Common;

namespace PersistentObject.StudentTest
{
    [TestClass]
    public class SchemaTest
    {
        [TestMethod]
        public void CreateTableInfo()
        {
            //DialectConfig config = new DialectConfig();
            //TableInfo r1 = SchemaHelper.CreateTableInfo<ClassA>(config);
            //Assert.AreEqual(r1.KeyColumn.Name == "Id", true);
            ////Assert.AreEqual(r1.ColumnList.Count == 8, true);
            //Assert.AreEqual(r1.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTableInfo.Name == "ClassB") != null, true);
            //Assert.AreEqual(r1.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTableInfo.Name == "ClassD") != null, true);
            //Assert.AreEqual(r1.ColumnList.Find((item) => item.Name == "ClassBId2" && item.IsForeignKeyColumn && item.ForeignTableInfo.Name == "ClassB") != null, true);

            //TableInfo r2 = SchemaHelper.CreateTableInfo < ClassB > config(config);
            //Assert.AreEqual(r2.KeyColumn.Name == "Id", true);
            //Assert.AreEqual(r2.ColumnList.Count == 7, true);
            //Assert.AreEqual(r2.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTableInfo.Name == "ClassB") != null, true);

            //TableInfo r3 = SchemaHelper.CreateTableInfo<ClassD>(config);
            //Assert.AreEqual(r3.KeyColumn.Name == "Id", true);
            //Assert.AreEqual(r3.ColumnList.Count == 7, true);
            //Assert.AreEqual(r3.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTableInfo.Name == "ClassE") != null, true);

            //TableInfo r4 = SchemaHelper.CreateTableInfo<ClassE>();
            //Assert.AreEqual(r4.KeyColumn.Name == "Id", true);
            //Assert.AreEqual(r4.ColumnList.Count == 7, true);
            //Assert.AreEqual(r4.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTableInfo.Name == "ClassD") != null, true);
        }

        [TestMethod]
        public void CreateTable()
        {
            //Table a = SchemaHelper.CreateTable<ClassA>();
            //Assert.AreEqual(a.KeyColumn.ColumnName == "Id", true);
            //Assert.AreEqual(a.Sequence == 0, true);
            //var a_classb = a.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassB");
            //Assert.AreEqual(a_classb != null, true);
            //var a_classd = a.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassD");
            //Assert.AreEqual(a_classd != null, true);
            //Assert.AreEqual(a.KeyColumn.Sequence == 0, true);
            //var a_image = a.ColumnList.Find((item) => item.ColumnName == "IMAGE");
            //Assert.AreEqual(a_image.Convertor != null, true);

            //Column r1B = a.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassB");
            //Column r1BB = r1B.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassB");
            //Column r1BBB = r1BB.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassB");
            //Column r1BBBB = r1BBB.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassB");
            //Column r1B2 = a.ColumnList.Find((item) => item.ColumnName == "ClassBId2" && item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassB");
            //Column r1BB2 = r1B2.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassB");
            //Column r1BBB2 = r1BB2.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassB");
            //Column r1BBBB2 = r1BBB2.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassB");
            //Column r1D = a.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassD");
            //Column r1DE = r1D.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassE");
            //Column r1DED = r1DE.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassD");
            //Column r1DEDE = r1DED.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassE");
            //Column r1DEDED = r1DEDE.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassD");
            //Column r1DEDEDE = r1DEDED.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassE");
            //Column r1DEDEDED = r1DEDEDE.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassD");
            ////Column r1DEDEDEDE = r1DEDEDED.ForeignTable.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.Name == "ClassE");

            //Assert.AreEqual(r1BB != null, true);
            //Assert.AreEqual(r1BBB != null, true);
            //Assert.AreEqual(r1BBBB == null, true);
            //Assert.AreEqual(r1BB2 != null, true);
            //Assert.AreEqual(r1BBB2 != null, true);
            //Assert.AreEqual(r1BBBB2 == null, true);
            //Assert.AreEqual(r1DE != null, true);
            //Assert.AreEqual(r1DED != null, true);
            //Assert.AreEqual(r1DEDE != null, true);
            //Assert.AreEqual(r1DEDED != null, true);
            //Assert.AreEqual(r1DEDEDE != null, true);
            //Assert.AreEqual(r1DEDEDED == null, true);
            ////Assert.AreEqual(r1DEDEDEDE == null, true);

            //Assert.AreEqual(r1B.ForeignTable.Sequence == 0, true);
            //Assert.AreEqual(r1B2.ForeignTable.Sequence == 1, true);
            //Assert.AreEqual(r1BB.ForeignTable.Sequence == 2, true);
            //Assert.AreEqual(r1BB2.ForeignTable.Sequence == 3, true);
            //Assert.AreEqual(r1BBB.ForeignTable.Sequence == 4, true);
            //Assert.AreEqual(r1BBB2.ForeignTable.Sequence == 5, true);

            //Assert.AreEqual(r1B.ForeignTable.KeyColumn.Sequence == 1, true);
            //Assert.AreEqual(r1B2.ForeignTable.KeyColumn.Sequence == 2, true);
            //Assert.AreEqual(r1D.ForeignTable.KeyColumn.Sequence == 3, true);
            //Assert.AreEqual(r1BB.ForeignTable.KeyColumn.Sequence == 4, true);
            //Assert.AreEqual(r1BB2.ForeignTable.KeyColumn.Sequence == 5, true);
            //Assert.AreEqual(r1DE.ForeignTable.KeyColumn.Sequence == 6, true);
            //Assert.AreEqual(r1BBB.ForeignTable.KeyColumn.Sequence == 7, true);
            //Assert.AreEqual(r1BBB2.ForeignTable.KeyColumn.Sequence == 8, true);
            //Assert.AreEqual(r1DED.ForeignTable.KeyColumn.Sequence == 9, true);

            //Table r2 = SchemaHelper.CreateTable<ClassB>();
            //Assert.AreEqual(r2.KeyColumn.ColumnName == "Id", true);
            //Assert.AreEqual(r2.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassB") != null, true);
            //Assert.AreEqual(r2.KeyColumn.Sequence == 0, true);

            //Table r3 = SchemaHelper.CreateTable<ClassD>();
            //Assert.AreEqual(r3.KeyColumn.ColumnName == "Id", true);
            //Assert.AreEqual(r3.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassE") != null, true);

            //Table r4 = SchemaHelper.CreateTable<ClassE>();
            //Assert.AreEqual(r4.KeyColumn.ColumnName == "Id", true);
            //Assert.AreEqual(r4.ColumnList.Find((item) => item.IsForeignKeyColumn && item.ForeignTable.TableName == "ClassD") != null, true);
        }
    }
}
